import top.malaoshi.data.DataColumn;
import top.malaoshi.data.DataQuery;
import top.malaoshi.data.DataRow;
import top.malaoshi.data.DataTable;
import top.malaoshi.util.Out;

public class S8测试索引查询 {
    static DataTable ready(){
        DataTable dt = new DataTable("t_user");
        Out.println("表名：",dt.getName());

//        dt.columns().add("id");
        dt.columns().add("id", DataColumn.Type.INT);
        dt.columns().add("username", DataColumn.Type.TEXT);
        dt.columns().add("password", DataColumn.Type.TEXT);
        dt.columns().add("age", DataColumn.Type.INT);
        dt.columns().add("height", DataColumn.Type.DOUBLE);
        dt.columns().add("birthday", DataColumn.Type.TEXT);

        dt.indexManager.addIndex("id");
        dt.indexManager.addIndex("age");
        dt.indexManager.addIndex("height");
        dt.indexManager.addIndex("password");

        dt.rows().add(new Object[]{1,"lilei","123456",20,1.83,"2000-06-01"});
        DataRow drHmm = dt.rows().add(new Object[]{2, "韩梅梅", "666", 22,1.65,"2000-07-01"});

        // 创建 DataRnow
        DataRow dataRow = dt.newRow();
        dt.rows().add(dataRow);
//        通过索引设置数据
        dataRow.setValue( 0,3 );
        dataRow.setValue( 1,"lucy" );
        dataRow.setValue( 2,"333" );
        dataRow.setValue( 3,22);
        dataRow.setValue( 4,1.73 );
        dataRow.setValue( 5,"2000-08-01" );

        // 创建 DataRnow
        DataRow dataRow2 = dt.newRow();

        dataRow2.setValue("id",4);
        dataRow2.setValue("username","lili");
        dataRow2.setValue("password","555");
        dataRow2.setValue("age",28);
        dataRow2.setValue("height",1.65);
        dataRow2.setValue("birthday","2000-09-01");

        dt.rows().add(new Object[]{5,"张三","123",20,1.83,"2000-10-01"});
        dt.rows().add(new Object[]{6,"李四","124",30,1.73,"2000-11-01"});
        dt.rows().add(new Object[]{7,"杜子腾","125",35,1.82,"2000-12-01"});
        dt.rows().add(new Object[]{8,"史珍香","126",19,1.68,"2000-03-01"});
        dt.rows().add(new Object[]{9,"小明","127",10,0.9,"2015-03-01"});
        dt.rows().add(new Object[]{10,"张大","123456",20,1.83,"2000-10-01"});

        return dt;
    }
    public static void main(String[] args) {
        DataTable table = ready();

        Out.println("索引",table.indexManager.getIndexes());

//        判断整数大于、大于等于、小于、小于等于、等于
//        DataRow[] drs = table.select("id", DataQuery.Option.eq, 1);
//        测试查询不到
//        DataRow[] drs = table.select("age", DataQuery.Option.eq, 301);
//        DataRow[] drs = table.select("age", DataQuery.Option.eq, 30);
//        DataRow[] drs = table.select("age", DataQuery.Option.lt, 30);
//        DataRow[] drs = table.select("age", DataQuery.Option.lte, 30);
//        DataRow[] drs = table.select("age", DataQuery.Option.gt, 30);
//        DataRow[] drs = table.select("age", DataQuery.Option.gte, 30);
//        DataRow[] drs = table.select("age", DataQuery.Option.neq, 30);

//        DataRow[] drs = table.select("height", DataQuery.Option.eq, 1.83);
//        找不到
//        DataRow[] drs = table.select("height", DataQuery.Option.eq, 1.731);
//        不存在大于的
//        DataRow[] drs = table.select("height", DataQuery.Option.gt, 3.73);
//        DataRow[] drs = table.select("height", DataQuery.Option.gt, 1.73);
//        DataRow[] drs = table.select("height", DataQuery.Option.gte, 1.73);
//        DataRow[] drs = table.select("height", DataQuery.Option.lt, 1.73);
//        DataRow[] drs = table.select("height", DataQuery.Option.lte, 1.73);
//        DataRow[] drs = table.select("height", DataQuery.Option.neq, 1.73);
//        查询不到
//        DataRow[] drs = table.select("password", DataQuery.Option.eq, "333---");
        //        查询不到
        DataRow[] drs = table.select("password", DataQuery.Option.lt, "0");
//        查询等于
//        DataRow[] drs = table.select("password", DataQuery.Option.eq, "333");
//        DataRow[] drs = table.select("password", DataQuery.Option.lt, "125");
//        DataRow[] drs = table.select("password", DataQuery.Option.lte, "125");
//        DataRow[] drs = table.select("password", DataQuery.Option.gt, "125");
//        DataRow[] drs = table.select("password", DataQuery.Option.gte, "125");
//        DataRow[] drs = table.select("password", DataQuery.Option.gte, "925");
//        DataRow[] drs = table.select("password", DataQuery.Option.neq, "925");
        Out.println("drs:",drs);
//        Out.println("drs2:",drs2);
//        Out.println("drs3:",drs3);
    }
}
